﻿CREATE TABLE [dbo].[AttValues] (
    [ID]       INT           IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL,
    [EntityID] INT           NOT NULL,
    [AttID]    INT           NOT NULL,
    [Value]    VARCHAR (MAX) NOT NULL,
    CONSTRAINT [PK_AttValues] PRIMARY KEY CLUSTERED ([ID] ASC),
    CONSTRAINT [FK__AttValues__AttID__123EB7A3] FOREIGN KEY ([AttID]) REFERENCES [dbo].[Attributes] ([ID]),
    CONSTRAINT [FK_AttValues_Entities] FOREIGN KEY ([EntityID]) REFERENCES [dbo].[Entities] ([EntityID])
);


GO
CREATE NONCLUSTERED INDEX [ix_EntityID_AttID]
    ON [dbo].[AttValues]([EntityID] ASC, [AttID] ASC)
    INCLUDE([ID]);


GO
CREATE NONCLUSTERED INDEX [ix_AttID]
    ON [dbo].[AttValues]([AttID] ASC);


GO
CREATE STATISTICS [stat_AttValue]
    ON [dbo].[AttValues]([Value]);

